package me.landery.modules.sinco.domain;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import me.landery.base.BaseEntity;
import me.landery.modules.system.domain.User;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Objects;

/**
 * @Author cc.w
 * @Date 2022/6/28 15:30
 * @Version 1.0
 */

@Entity
@Data
@Table(name="sinco_cert")
public class Cert extends BaseEntity implements Serializable {
    @Id
    @Column(name = "cert_id", nullable = false)
    @NotNull(groups = BaseEntity.Update.class)
    @ApiModelProperty(value = "实名认证ID", hidden = true)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id")
    @ApiModelProperty(value = "身份证对应的用户")
    private User user;

    @NotBlank
    @ApiModelProperty(value = "身份证真实姓名")
    private String realname;

    @NotBlank
    @ApiModelProperty(value = "身份证号码")
    private String certnum;

    @NotBlank
    @ApiModelProperty(value = "身份证正面")
    private String imgFront;

    @NotNull
    @ApiModelProperty(value = "身份证反面")
    private String imgBack; //额度

    @ApiModelProperty(value = "审核状态")
    private Integer status;

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Cert call = (Cert) o;
        return Objects.equals(id, call.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }

    public void copy(Cert source){
        BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
    }
}
